﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CKFinder;


public partial class Admin_Orderdetail : System.Web.UI.Page
{
    OrderController order = new OrderController();
    OrderDetailController orderdetail = new OrderDetailController();
    public Orders o = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        CKFinder.FileBrowser fb = new FileBrowser();
        fb.BasePath = "../ckfinder/";
        fb.SetupCKEditor(ckeditor_description);
        string id = Request.QueryString["id"];

        if(!IsPostBack)
        {
            int idd = Convert.ToInt32(id);
            if(checkId(idd))
            {
                DataTable dt=order.GetByID(idd);
                o=new Orders(dt.Rows[0]);
                txtFullname.Text = o.Username;
                txtAddress.Text = o.Address;
                txtPhone.Text = o.Phone;
                txtEmail.Text = o.Email;
                ckeditor_description.Text = o.Description;
                txtDateStart.Text = DateTime.Parse(o.DateStart.ToString()).ToString();

                DataTable dtOrderdetail = orderdetail.GetByOrderID(idd);
                grvOrderdetail.DataSource = dtOrderdetail;
                grvOrderdetail.DataBind();
            }
            else
            {
                error();
            }
        }
    }

    public void error()
    {
        Response.Redirect("~/Error.aspx");
    }
    public bool checkId(int id)
    {
        DataTable dt = order.GetByID(id);
        if (dt.Rows.Count > 0)
        {
            return true;
        }
        return false;
    }
}